<template>
    <view>
        <block v-if="detail != null">
            <view class="padding-horizontal-main padding-top-main">
                <!-- 地址 -->
                <view  class="address bg-white padding-horizontal-main padding-top-main border-radius-main spacing-mb">
                    <view class="address-base oh">
                        <text  class="address-alias round br-main cr-main bg-white margin-right-sm">{{detail.address_data.alias}}</text>
                        <text>{{detail.order_no}}</text>
                        <text class="fr"></text>
                    </view>
                    <view class="address-detail oh margin-bottom-main">
                        <image class="icon fl" :src="common_static_url+'map-icon.png'" mode="widthFix"></image>
                        <view class="text fr">
                            <text>{{detail.cus_name}}({{detail.cus_code}})</text>
<!--                            <text class="address-map-submit cr-base br round bg-white margin-left-sm text-size-xs" @tap="address_map_event">查看位置</text> -->
                        </view>
                    </view>
                    <view class="address-divider spacing-mb"></view>
                </view>
				
				<!-- 订单基础数据 -->	
				<view v-if="detail_list.length > 0" class="panel-item padding-main border-radius-main bg-white spacing-mb">
<!-- 				    <view class="br-b padding-bottom-main fw-b text-size">订单信息</view> -->
				    <view class="panel-content oh">
				        <view v-for="(item, index) in detail_list" :key="index" class="item br-b-dashed oh padding-vertical-main">
				            <view class="title fl padding-right-main cr-gray">{{item.name}}</view>
				            <view class="content fl br-l padding-left-main">{{item.value}}</view>
				        </view>
				    </view>
				</view>
				
                <!-- 商品列表 -->
				<view >商品信息(共{{detail.sunqty}}种)</view>
                <view class="goods bg-white padding-main border-radius-main spacing-mb">
					<uni-table>
						<uni-tr>
							<uni-th width="90px">商品名</uni-th>
							<uni-th width="80px">下单数</uni-th>
							<uni-th width="50px">单价</uni-th>
							<uni-th width="80px">备注</uni-th>
							<uni-th width="50px">小计</uni-th>
						</uni-tr>
						
						<uni-tr v-for="(item,index) in detail.items" :key="index">
							<uni-td>{{item.materialName}}</uni-td>
							<uni-td>{{item.qty}}{{item.unitName}}</uni-td>
							<uni-td>{{currency_symbol}}{{item.settlePrice}}</uni-td>
							<uni-td>{{item.remark}}</uni-td>
							<uni-td>{{item.sendAmt}}</uni-td>
						</uni-tr>
					</uni-table>

                    <view class="padding-top-main tr cr-base text-size">
                        <text>共<text class="fw-b">{{detail.buy_number_count}}</text>件 合计 <text class="sales-price margin-right-xs">{{currency_symbol}}{{detail.total_price}}</text>元</text>
                    </view>
                </view>






            </view>

            <!-- 结尾 -->
            <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
        </block>
        <block v-else>
            <!-- 提示信息 -->
            <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
        </block>
    </view>
</template>
<script>
    const app = getApp();
    import componentNoData from "../../components/no-data/no-data";
    import componentBottomLine from "../../components/bottom-line/bottom-line";
	

    var common_static_url = app.globalData.get_static_url('common');
    export default {
        data() {
            return {
				share_info: {},
				user: null,
                common_static_url: common_static_url,
                params: null,
                data_list_loding_status: 1,
                data_list_loding_msg: '',
                data_bottom_line_status: false,
                detail: null,
                detail_list: [],
                extension_data: [],
				currency_symbol: app.globalData.data.currency_symbol,
                site_fictitious: null
            };
        },

        components: {
            componentNoData,
            componentBottomLine
        },
        props: {},

        onLoad(params) {
			// this.user =app.globalData.get_user_cache_info(),
            //params['id'] = 5;
            this.setData({
                params: params
            });
        },

        onShow() {
            // 数据加载
            this.init();
            
            // 分享菜单处理
			this.setData({
			    share_info: {
					title:'订单详情',
			        path: '/pages/user-order-detail/user-order-detail?id='+this.params.id
			    }
			});
            app.globalData.page_share_handle(this.share_info);
        },

        // 下拉刷新
        onPullDownRefresh() {
            this.init();
        },

        methods: {
            // 获取数据
            init() {
                var self = this;
                uni.showLoading({
                    title: '加载中...'
                });
                this.setData({
                    data_list_loding_status: 1
                });
				console.log("-------")
				uni.hideLoading();
                uni.request({
                    url: app.globalData.get_request_url("getOrderDetail"),
                    method: 'POST',
                    data: {
                        id: this.params.id
                    },
                   dataType: 'json',
					header:{
						// 'Tenant-Id':this.user.role.tenantId,
						// 'X-Access-Token':this.user.token,
					},
                    success: res => {
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
						console.log("-----",res)
                        if (res.data.code == 0) {
                            var data = res.data.data;
							console.log("---1111--",data)
							// {name: "订单编号", value: data.order_no || ''},
                            self.setData({
                                detail: data,
                                detail_list:[

                                    {name: "配送时间", value: data.bill_date.substring(0,11) || ''},
									{name: "下单时间", value: data.create_time || ''},
                                ],
                                // extension_data: data.data.extension_data || [],
                                data_list_loding_status: 3,
                                data_bottom_line_status: true,
                                data_list_loding_msg: ''
                            });
                        } else {
                            self.setData({
                                data_list_loding_status: 2,
                                data_bottom_line_status: false,
                                data_list_loding_msg: res.data.msg
                            });
                            if (app.globalData.is_login_check(res.data, self, 'init')) {
                                app.globalData.showToast(res.data.msg);
                            }
                        }
                    },
                    fail: () => {
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: '服务器请求出错'
                        });
                        app.globalData.showToast('服务器请求出错');
                    }
                });
            },
        
        }
    };
</script>
<style>
    @import './user-order-detail.css';
</style>